<template>
	<view>
		<baseForm :column.sync="column" :button="button"></baseForm>
		<progressBox :auditVos="auditVos" dictcode="dict_audit_status"></progressBox>
		<view class="buttons" v-if="user.roleType == 0 && companyInfo.applyStatus == 1">
			<button size="mini" class="middleButton" @click="pass">通过</button>
			<button size="mini" class="middleButton" @click="noPass">不通过</button>
		</view>
	</view>
</template>

<script>
import baseForm from '@/wxcomponents/form/form.vue';
import login from '@/libs/login.js';
import progressBox from '@/wxcomponents/commonLayout/progressLevel.vue';
export default {
	data() {
		return {
			auditVos: '',
			column: [
				{
					label: '申请人',
					name: 'studentName',
					type: 'normalInput',
					disabled: true,
					value: ''
				},
				{
					label: '企业名称',
					name: 'practiceEnterpriseName',
					type: 'normalInput',
					disabled: true,
					value: ''
				},
				{
					label: '企业联系人',
					name: 'enterpriseContact',
					type: 'normalInput',
					disabled: true,
					value: ''
				},
				{
					label: '企业联系人电话',
					name: 'enterprisePhone',
					type: 'normalInput',
					disabled: true,
					value: ''
				},
				{
					label: '所在省市',
					name: 'enterpriseAreaCity',
					type: 'normalInput',
					disabled: true,
					value: ''
				},
				{
					label: '企业地址',
					name: 'enterpriseAddress',
					type: 'normalInput',
					disabled: true,
					value: ''
				},
				{
					label: '实习负责人',
					name: 'practicePrincipal',
					type: 'normalInput',
					disabled: true,
					value: ''
				},
				{
					label: '实习负责人电话',
					name: 'practicePrincipalPhone',
					type: 'normalInput',
					disabled: true,
					value: ''
				},
				{
					label: '实习时间',
					name: 'practiceTime',
					type: 'normalInput',
					disabled: true,
					value: ''
				},
				{
					label: '实习岗位',
					name: 'practicePosition',
					type: 'normalInput',
					required:true,
					disabled: false,
					value: ''
				},
				{
					label: '指导老师',
					name: 'practiceAdviser',
					type: 'normalInput',
					required:true,
					disabled: false,
					value: ''
				},
				{
					label: '保险险种名称',
					name: 'practiceInsureName',
					type: 'normalInput',
					disabled: false,
					value: ''
				},
				{
					label: '保险费出资方',
					name: 'practiceInsureInvestor',
					type: 'normalInput',
					disabled: false,
					value: ''
				}
			],
			button: {
				hide: true
			},
			companyInfo: '',
			user: ''
		};
	},
	async onShow() {
		//待审批--1；已通过--2；未通过--3
		let option = this.getPageOptions();
		this.companyInfo = JSON.parse(option.data);
		console.log(this.companyInfo);
		let user = await login.getStorage('user');
		this.user = user;
		this.setColumn(user);
		this.setColumn(this.companyInfo);
		this.setColumn(this.companyInfo.enterprise);
		this.setColumnTime(this.companyInfo.enterprise);
		this.getDetail();
	},
	methods: {
		async getDetail() {
			let resp = await this.$http.get({
				url: `/enrollment/practiceApply/detail/${this.companyInfo.id}`
			});
			this.auditVos = resp.result.auditVos;
		},
		setColumn(data) {
			this.column.forEach(item => {
				if (data[item.name]) {
					item.value = data[item.name];
				}
			});
		},
		setColumnTime(data) {
			this.column.forEach(item => {
				if (item.name == 'practiceTime') {
					item.value = data.practiceStartTime.split(' ')[0] + '至' + data.practiceEndTime.split(' ')[0];
				}
			});
		},
		async pass() {
			let resp = await this.$http.post({
				url: '/enrollment/practiceApply/approval',
				data: {
					id: this.companyInfo.id,
					applyStatus: 2,
					practicePosition:this.column[9].value,
					practiceAdviser:this.column[10].value,
					practiceInsureName:this.column[11].value,
					practiceInsureInvestor:this.column[12].value
					
				}
			})
			this.showToast('提交成功',()=> {uni.navigateBack()});
		},
		async noPass() {
			let resp = await this.$http.post({
				url: '/enrollment/practiceApply/approval',
				data: {
					id: this.companyInfo.id,
					applyStatus: 3
				}
			});
			this.showToast('提交成功',()=> {uni.navigateBack()});
		}
	},
	components: {
		baseForm,
		progressBox
	}
};
</script>

<style lang="scss" scoped>
.buttons {
	width: 650upx;
	margin: 20upx auto;
	display: flex;
	justify-content: space-between;
}
</style>
